<?php
/**
 * 客户代理人
 * @author Administrator
 *
 */
class Application_Model_DbTable_Custagent extends Application_Model_DbTable_Base
{
    protected $_name = 'customer_agent';
    
	/**
	 * 根据email获取customer agent
	 * @param string $mail
	 * @return Zend_Db_Table_Row_Abstract|null 
	 */
	public function getItemByMail($mail)
	{
		$select = $this->select();
		$select->where(" `email`=?",$mail);
		return $this->fetchRow($select);
	}
	
	/**
	 * 根据eamil返回客户
	 * @param string $mail
	 * @return Zend_Db_Table_Row_Abstract|null  
	 */
	public function getCustomerByMail($mail)
	{
		$agent = $this->getItemByMail($mail);
		if($agent){
			$customerId = $agent->customer;
			$customerM  = new Application_Model_DbTable_Customer(); 
			return $customerM->fetchRow(" `id`={$customerId} ");
		}
		return NULL;
	}
}

